<template>

    <el-button size="default" type="default" @click="backToList()">返回</el-button>
    <el-button size="default" type="default" @click="getDetail()">获取数据</el-button>

    <el-descriptions column="2">
        <el-descriptions-item label="头像">
            <el-image :src="dataDetail.headUrl"></el-image>
        </el-descriptions-item>

    </el-descriptions>

    <el-descriptions column="3">
        <el-descriptions-item label="id：">{{ dataDetail.id }}</el-descriptions-item>
        <el-descriptions-item label="用户名：">{{ dataDetail.userName }}</el-descriptions-item>
        <el-descriptions-item label="性别：">{{ genderMap.get(dataDetail.userGender) }}</el-descriptions-item>
        <el-descriptions-item label="账号：">{{ dataDetail.account }}</el-descriptions-item>
        <el-descriptions-item label="身份：">{{ identityMap.get(dataDetail.identity) }}</el-descriptions-item>
        <el-descriptions-item label="真实姓名：">{{ dataDetail.realName }}</el-descriptions-item>
        <el-descriptions-item label="身份证号：">{{ dataDetail.identityNum }}</el-descriptions-item>
        <el-descriptions-item label="邮箱：">{{ dataDetail.email }}</el-descriptions-item>
        <el-descriptions-item label="电话：">{{ dataDetail.phone }}</el-descriptions-item>
        <el-descriptions-item label="状态：">{{ statusMap.get(dataDetail.status) }}</el-descriptions-item>
        <el-descriptions-item label="信用分：">{{ dataDetail.credit }}</el-descriptions-item>
        <el-descriptions-item label="注册时间：">{{ dataDetail.gmtCreateTime }}</el-descriptions-item>
    </el-descriptions>


    <el-form-item>
        <el-button type="primary" @click="limit(route.params.id, '1')">
            恢复正常
        </el-button>
        <el-button type="danger" @click="limit(route.params.id, '2')">
            禁用账号
        </el-button>
        <el-button type="danger" @click="wait()">
            拉入黑名单
        </el-button>
    </el-form-item>

</template>

<script setup>

import { ref } from 'vue'
import {useRoute, useRouter} from "vue-router";
import {changeStatus, getPostList} from "@/api/request";
import {ElMessage} from "element-plus";

const loginUserId = ref("")
const loginUserName = ref("")
const router = useRouter()
const route = useRoute()
const id = route.params.id


const genderMap = ref(new Map([
    ['0', "保密"],
    ['1', "男"],
    ['2', "女"]
]))
const identityMap = ref(new Map([
    ['0', "普通用户"],
    ['1', "管理员"],
    ['3', "超级管理员"]
]))
const statusMap = ref(new Map([
    ['0', "待激活"],
    ['1', "正常"],
    ['2', "屏蔽"]
]))

const reqParam = ref({
    loginUserId: "",
    loginUserName: "",
    id: ""
})

const dataDetail = ref({
    id: "1",
    userName: "无敌暴龙战神",
    account: "sushi",
    password: "",
    userGender: "1",
    identity: "3",
    credit: 100,
    realName: "委委员",
    identityNum: "3",
    email: "sushi51@163.com",
    phone: "19812345678",
    amount: 0.0,
    status: "1",
    creatorId: "",
    creatorName: "",
    gmtCreateTime: "2022-09-01",
    modifierId: "",
    modifierName: "",
    gmtModifyTime: ""
})
async function getDetail() {
    let resp = await getPostList({
        // id: id.values()
        id: route.params.id
    }, "/user/detail")
    console.log(resp)
    dataDetail.value = resp.data
}
function backToList() {
    router.back()
}


async function limit(reqId, reqStatus) {
    let resp = await changeStatus(
        {
            id: reqId,
            status: reqStatus
        }, "/user/update"
    )
    console.log(resp)
    if (resp.code === 200) {
        ElMessage.success("更新成功")
    }else {
        ElMessage.error("更新失败")
    }
}

function wait() {
    ElMessage.info("功能开发中，敬请期待....")
}


</script>


<style scoped>

</style>